package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HomeFlGridAdapter extends BaseAdapter {


    private Context mContext;
    List<HomeMerBean.CanListBean> mApListBeans;

    public HomeFlGridAdapter(Context context, List<HomeMerBean.CanListBean> mApListBeans) {
        this.mContext = context;
        this.mApListBeans = mApListBeans;
    }

    @Override
    public int getCount() {
        return mApListBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return mApListBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_home_fl_grid, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final HomeMerBean.CanListBean bean = mApListBeans.get(position);
        GlideUtils.loadCircleImg(mContext, holder.image, bean.getImg(), R.mipmap.icon_default_pic);
        holder.tv.setText(bean.getTitle());

        return convertView;
    }


    class ViewHolder {

        @BindView(R.id.image)
        ImageView image;
        @BindView(R.id.tv)
        TextView tv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
